package com.chuji.crmcj.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.chuji.crmcj.R;
import com.chuji.crmcj.utils.CommonUtil;
import com.chuji.crmcj.utils.UIUtils;

/**
 * Created by w.pitt on 2016/1/11.
 */
public class ToolsAdapter extends BaseAdapter {

    private String[] mHomeNames = new String[]{"车型库存", "通知公告", "战败审批",
            "贷款计算器", "保险计算器", "工作报表"};
    private int[] mImageIds = new int[]{R.drawable.i1,
            R.drawable.i2, R.drawable.i3,
            R.drawable.i4, R.drawable.i5,
            R.drawable.i6};

    private String[] mMagNames = new String[]{"工作报表", "通知公告", "车型库存"};
    private int[] mMagImage = new int[]{R.drawable.i6, R.drawable.i2, R.drawable.i1};

    private int lable = -1;

    public ToolsAdapter(int i) {
        this.lable = i;
    }

    public int mMessCount;

    public ToolsAdapter(int i, int messageCount) {
        this.lable = i;
        this.mMessCount = messageCount;
    }

    @Override
    public int getCount() {
        if (lable == 3) {
            return mMagNames.length;
        } else {
            return mHomeNames.length;
        }
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        view = view.inflate(UIUtils.getContext(), R.layout.item_function, null);
        TextView tvName = (TextView) view.findViewById(R.id.tv_name);
        ImageView ivIcon = (ImageView) view.findViewById(R.id.iv_icon);
        if (lable == 3) {

            tvName.setText(mMagNames[position]);
            ivIcon.setImageResource(mMagImage[position]);
        } else {
            tvName.setText(mHomeNames[position]);
            ivIcon.setImageResource(mImageIds[position]);
        }

        if (position == 1) {
            CommonUtil.setRedIcon(ivIcon, mMessCount);
        }

        return view;
    }

    public int getNotices() {
        return mMessCount;
    }
}
